import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useRef } from "react";
import AntToolTip from "~/public/cpas-ui/components-ui/ant-components/AntToolTip";
import CpasIcon from "~/public/cpas-ui/components-ui/components/Icon";
import { InputNumber } from "antd";
import DropDownButton from "devextreme-react/drop-down-button";
import { Button } from "devextreme-react/button";
import SelectBox from "devextreme-react/select-box";
import { Popover } from "devextreme-react/popover";
import ColorBox from "devextreme-react/color-box";
import { getCurrentSysName, SystemName, MergeType, getHbTypeByZcbfid, } from "../../../../tools/Tools";
// 点击文字后的弹出框
const renderWenziPopOver = (_this, wenziFontRef) => {
    return (_jsx(Popover, { target: wenziFontRef.current, position: "bottom", width: 350, visible: _this.state.wenziPanelVisible, onHiding: _this.hideWenZiPanel, shading: true, shadingColor: "rgba(0, 0, 0, 0.5)", children: _jsxs("div", { className: "wenzi-container", children: [_jsxs("div", { className: "wenzi-row row-bottom", children: [_jsx("div", { className: "wenzi-text", children: "\u5B57\u5F62:" }), _jsx("div", { className: "wenzi-select-area", children: _jsx(SelectBox, { placeholder: "", displayExpr: "name", valueExpr: "id", items: _this.zixingData, value: _this.state.it, className: "select-box-style-min", onItemClick: (e) => {
                                    _this.tableEditorService?.zixingChange(e);
                                } }) })] }), _jsxs("div", { className: "wenzi-row row-bottom", children: [_jsx("div", { className: "wenzi-text", children: "\u5B57\u4F53\u989C\u8272:" }), _jsx("div", { className: "wenzi-select-area", children: _jsx(ColorBox, { value: _this.state.fc, applyValueMode: "instantly", onClosed: (event) => {
                                    _this.tableEditorService?.setColorToCell();
                                }, onValueChanged: _this.tableEditorService?.handleColorChange }) })] }), _jsxs("div", { className: "wenzi-row", children: [_jsx("div", { className: "wenzi-text", children: "\u80CC\u666F\u989C\u8272:" }), _jsx("div", { className: "wenzi-select-area", children: _jsx(ColorBox, { value: _this.state.bg, applyValueMode: "instantly", onValueChanged: _this.tableEditorService?.handleBgColorChange, onClosed: (event) => {
                                    _this.tableEditorService?.setBgColorToCell();
                                } }) })] })] }) }));
};
// 表编辑
const TableEditor = ({ _this }) => {
    const wenziFontRef = useRef();
    const handleWenZiClick = () => {
        _this.showWenZiPanel();
    };
    const row = _this.gridRef?.state?.currentRecord?.coords?.row;
    const gridData = _this?.gridRef?.hot?.getData();
    let _lastCfg = {}; //获取最后一行配置，用来控制插行的条件限制
    if (row && gridData && gridData.length) {
        const currentData = gridData[row];
        _lastCfg = currentData
            ? JSON.parse(currentData[currentData.length - 1])
            : {};
    }
    const ro = _this.state.ro;
    let nxClassName = "tools-item";
    if (ro === true) {
        nxClassName = "tools-item cpas-menu-item-active";
    }
    else if (ro === false) {
        nxClassName = "tools-item cpas-menu-item-half-active";
    }
    else {
        nxClassName = "tools-item";
    }
    const sysName = getCurrentSysName();
    const mergeType = getHbTypeByZcbfid();
    return (_jsx(_Fragment, { children: _jsxs("div", { className: "col col1", children: [_jsx("div", { className: "row row1", children: _jsx("span", { children: "\u8868\u7F16\u8F91" }) }), _jsxs("div", { className: "tools-item-container", children: [_jsxs("div", { className: "row row2", children: [_jsx(AntToolTip, { placement: "top", title: "\u8868\u5934\u5C45\u5DE6\u5BF9\u9F50", children: _jsx("div", { className: _this.state.headerHt === 1
                                            ? "tools-item cpas-menu-item-active"
                                            : "tools-item", onClick: () => {
                                            _this.tableEditorService?.setHeaderAlign(1);
                                        }, children: _jsx(CpasIcon, { type: "icon-zuoduiqi", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "top", title: "\u8868\u5934\u5C45\u4E2D\u5BF9\u9F50", children: _jsx("div", { className: _this.state.headerHt === 2
                                            ? "tools-item cpas-menu-item-active"
                                            : "tools-item", onClick: () => {
                                            _this.tableEditorService?.setHeaderAlign(2);
                                        }, children: _jsx(CpasIcon, { type: "icon-juzhong", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "top", title: "\u8868\u5934\u5C45\u53F3\u5BF9\u9F50", children: _jsx("div", { className: _this.state.headerHt === 3
                                            ? "tools-item cpas-menu-item-active"
                                            : "tools-item", onClick: () => {
                                            _this.tableEditorService?.setHeaderAlign(3);
                                        }, children: _jsx(CpasIcon, { type: "icon-youduiqi", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "top", title: "\u8868\u5934\u52A0\u7C97", children: _jsx("div", { className: _this.state.headerBl === 2
                                            ? "tools-item cpas-menu-item-active"
                                            : "tools-item", onClick: () => {
                                            _this.tableEditorService?.setHeaderBold(1);
                                        }, children: _jsx(CpasIcon, { type: "icon-jiacu", className: "cpas-icon" }) }) }), _jsxs(AntToolTip, { placement: "top", title: "\u6587\u5B57", children: [_jsx("div", { className: "tools-item", id: "wenziFont", ref: wenziFontRef, children: _jsx(CpasIcon, { type: "icon-wenzi", className: "cpas-icon", onClick: handleWenZiClick }) }), renderWenziPopOver(_this, wenziFontRef)] }), _jsxs("div", { className: "tools-item-inline", children: [_jsx("span", { style: { minWidth: 84 }, children: "\u51BB\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u00A0\u7ED3" }), _jsx(InputNumber, { height: 24, size: "middle", min: 0, max: 10, className: "tool-number-input", value: _this.state.fixedColumnsStart, onChange: _this.setFixedColumnsStart })] }), _jsx("div", { className: "tools-item-inline", children: _jsx(DropDownButton, { text: "\u63D2\u884C", icon: "iconfont icon-chahang", dropDownOptions: _this.buttonDropDownOptions, displayExpr: "name", items: _lastCfg?.operator_r?.operatorTag
                                            ? [_this.insertRowsOptions[1]]
                                            : _this.insertRowsOptions, onItemClick: (e) => {
                                            _this.tableEditorService?.insertRowsHandle(e, true);
                                        } }) }), (sysName === SystemName.SINGLE ||
                                    mergeType === MergeType.TEMPLATE) && (_jsx("div", { className: "tools-item-inline", children: _jsx(DropDownButton, { text: "\u63D2\u5217", icon: "iconfont icon-chalie", dropDownOptions: _this.buttonDropDownOptions, displayExpr: "name", items: _this.insertColumnOptions, onItemClick: (e) => {
                                            _this.insertColumnHandle(e, true);
                                        } }) }))] }), _jsxs("div", { className: "row row3", children: [_jsx(AntToolTip, { placement: "bottom", title: "\u5C45\u5DE6\u5BF9\u9F50", children: _jsx("div", { className: _this.state.ht === 1
                                            ? "tools-item cpas-menu-item-active"
                                            : "tools-item", onClick: () => {
                                            _this.tableEditorService?.setCellAlign(1);
                                        }, children: _jsx(CpasIcon, { type: "icon-zuoduiqi", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u5C45\u4E2D\u5BF9\u9F50", children: _jsx("div", { className: _this.state.ht === 2
                                            ? "tools-item cpas-menu-item-active"
                                            : "tools-item", onClick: () => {
                                            _this.tableEditorService?.setCellAlign(2);
                                        }, children: _jsx(CpasIcon, { type: "icon-juzhong", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u5C45\u53F3\u5BF9\u9F50", children: _jsx("div", { className: _this.state.ht === 3
                                            ? "tools-item cpas-menu-item-active"
                                            : "tools-item", onClick: () => {
                                            _this.tableEditorService?.setCellAlign(3);
                                        }, children: _jsx(CpasIcon, { type: "icon-youduiqi", className: "cpas-icon" }) }) }), _jsx(AntToolTip, { placement: "bottom", title: "\u6587\u672C\u52A0\u7C97", children: _jsx("div", { className: _this.state.bl === 2
                                            ? "tools-item cpas-menu-item-active"
                                            : "tools-item", onClick: () => {
                                            _this.tableEditorService?.setCellFontBold();
                                        }, children: _jsx(CpasIcon, { fill: "red", type: "icon-jiacu", className: "cpas-icon" }) }) }), sysName !== SystemName.MERGE &&
                                    _this.gridRef.props.type === "ds" ? (_jsx(AntToolTip, { placement: "bottom", title: "\u9006\u5E8F", children: _jsx("div", { className: nxClassName, onClick: () => {
                                            _this.tableEditorService?.setReverseOrder();
                                        }, children: _jsx(CpasIcon, { fill: "red", type: "icon-nixu", className: "cpas-icon" }) }) })) : (_jsx("div", { className: "tools-item" })), _jsx(AntToolTip, { placement: "bottom", title: "\u53EA\u6709\u6587\u672C\u5217\u53EF\u88AB\u7F29\u8FDB", children: _jsxs("div", { className: "tools-item-inline", children: [_jsx("div", { className: "tools-item-inline", children: _jsx(DropDownButton, { stylingMode: "text", displayExpr: "name", keyExpr: "id", useSelectMode: true, selectedItemKey: _this.state.r.type, items: _this.indentation, onItemClick: (e) => {
                                                        const itemData = e.itemData;
                                                        const val = {
                                                            r: {
                                                                type: itemData.id,
                                                                val: _this.state.r.val,
                                                            },
                                                        };
                                                        _this.setState({
                                                            ...val,
                                                        });
                                                        const currentRange = _this.gridRef.state.currentRange;
                                                        // this.gridService.setRetractToCell(value, currentRange);
                                                        _this.gridService.setCellConfig({
                                                            ...val,
                                                        }, currentRange);
                                                    } }) }), _jsx(InputNumber, { size: "middle", className: "tool-number-input", value: _this.state.r.val, onChange: _this.setCellRetract })] }) }), _jsx("div", { className: "tools-item-inline", children: _jsx(Button, { icon: "iconfont icon-shanhang", stylingMode: "text", text: "删行", onClick: _this.removeRowHandle, style: { marginRight: 22 } }) }), (sysName === SystemName.SINGLE ||
                                    mergeType === MergeType.TEMPLATE) && (_jsx("div", { className: "tools-item-inline", children: _jsx(Button, { icon: "iconfont icon-shanlie", stylingMode: "text", onClick: () => _this.removeColumnHandle(), text: "删列" }) }))] })] })] }) }));
};
export default TableEditor;
